package com.qqonline.conmon.async;

import org.json.JSONObject;

import com.qqonline.conmon.getUrlResponse;

import android.os.AsyncTask;
import android.util.Log;

public class AsyncTaskPost extends AsyncTask<String, Integer, String> {

	private final static String TAG="AsyncTaskPost";
	private DoPostBack _postback;
	private getUrlResponse post;
	private boolean isFinished;
	private boolean isStoped;
	public AsyncTaskPost(DoPostBack postback) {
		_postback=postback;
		post=new getUrlResponse();
		isFinished=false;
		isStoped=false;
	}
	public boolean isTaskFinished()
	{
		return isFinished;
	}
	public void stop()
	{
		Log.i(TAG,"stop");
		post.stopCurrentPostClient();
		isStoped=true;
	}
	@Override
	protected String doInBackground(String... params) {
		Log.i(TAG,"doInBackground");
		String jsonString=null;
		try {
			if (isStoped) {
				return null;
			}
			jsonString= post.postUtfString(params[0]);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		return jsonString;
	}
	@Override
	protected void onPostExecute(String result) {
		Log.i(TAG,"onPostExecute");
		_postback.PostBack(result);
		isFinished=true;
	}
	public interface DoPostBack
	{
		public void PostBack(String result);
	}

}
